import {fileURLToPath, URL} from 'node:url'

import {defineConfig, loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
import eslintPlugin from 'vite-plugin-eslint'

import path from 'path'
import {createSvgIconsPlugin} from "vite-plugin-svg-icons";

export default defineConfig(({ mode})=>{
    let env = loadEnv(mode, process.cwd())
    return {
        plugins: [
            vue(),
            vueDevTools(),
            eslintPlugin({
                include: ['src/**/*.ts', 'src/**/*.vue', 'src/*.ts', 'src/*.vue']
            }),
            createSvgIconsPlugin({
                iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
                symbolId: 'icon-[dir]-[name]'
            })
        ],
        server: {
            port: 9527,
            proxy: {
                [env.VITE_APP_BASE_API]: {
                    target: env.VITE_APP_BASE_URL,
                    changeOrigin: true,
                    rewrite:(path) => path.replace(/^\/api/, '')
                }
            }
        },
        resolve: {
            alias: {
                '@': fileURLToPath(new URL('./src', import.meta.url))
            },
        },
        css: {
            preprocessorOptions: {
                scss: {
                    additionalData: `@use "@/styles/variable.scss" as *;`
                }
            }
        }
    }
})
